<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of topographics_areas
 *
 * @author wilavel
 */
class TopographicAreasController extends AppController {
    //put your code here
    var $name="TopographicAreas";
    function index($topographic_map_id,$property_id) {
        $this->set('property_id',$property_id);
        $this->set('topographic_map_id',$topographic_map_id);
        $this->set('cod', $this->TopographicArea->TopographicMap->Property->field('codigo', array('Property.id' => $property_id)));
        $this->TopographicArea->recursive = 0;
        $this->set('areas',$this->TopographicArea->find('all',array('conditions'=>array('TopographicArea.topographic_map_id'=>$topographic_map_id), 'fields'=>array('TopographicArea.magnitud','TopographicMap.cerrado','AreaType.nombre', 'TopographicArea.id'))) );
        
    }
    
    
    function add($topographic_map_id,$property_id){
        
        $this->set('property_id',$property_id);
        $this->set('topographic_map_id',$topographic_map_id);   
        $this->set('areaTypes',$this->TopographicArea->AreaType->find('list',array('fields'=>array('AreaType.id', 'AreaType.nombre'))));
        if(!empty($this->data)){
            if($this->TopographicArea->saveAll($this->data)){
                $this->Session->setFlash('Registro guardado correctamente');
                $this->redirect(array('controller'=>'TopographicAreas','action'=>'index',$topographic_map_id,$property_id));
           
           }else{
               $this->Session->setFlash('No fue posible guardar el área por favor verifique los datos.');
           }
        }
        
        
    }
    
    
    function edit($id,$property_id){
        $this->set('property_id',$property_id);
        $this->set('id',$id);   
        $this->set('areaTypes',$this->TopographicArea->AreaType->find('list',array('fields'=>array('AreaType.id', 'AreaType.nombre'))));
        if(!empty($this->data)){
            if($this->TopographicArea->saveAll($this->data)){
                $this->Session->setFlash('Registro guardado correctamente');
                $this->redirect(array('controller'=>'TopographicAreas','action'=>'index',$this->data['TopographicArea']['topographic_map_id'],$property_id));
            }
        }else{
            $this->TopographicArea->recursive=-1;
            $this->data=$this->TopographicArea->find('first',array('conditions'=>array('TopographicArea.id'=>$id)));
        }
    }
    
    
    function delete($id,$property_id,$topographic_map_id){
         
            if($this->TopographicArea->delete($id)){
                $this->Session->setFlash('Registro borrado correctamente');
                $this->redirect(array('controller'=>'TopographicAreas','action'=>'index',$topographic_map_id,$property_id));
            }
        
    }
    
    
}

?>
